package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.ShopCartDao;
import com.itheima.pojo.ShopCart;
import com.itheima.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class CartServiceImpl implements CartService {

    @Autowired
    private ShopCartDao shopCartDao;
    @Override
    public PageInfo<ShopCart> findByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<ShopCart> list = shopCartDao.findAll();
        return new PageInfo<>(list);
    }

    @Override
    public int selectAll(int index) {
        return shopCartDao.selectAll(index);
    }

    @Override
    public int selectOne(int index, int id) {
        return shopCartDao.selectOne(index,id);
    }

    @Override
    public int save(ShopCart shopCart) {
        shopCart.setIsDelete(0);
        shopCart.setUserId(1L);
        shopCart.setContentId(1);
        return shopCartDao.save(shopCart);
    }

    @Override
    public int delete(int id) {
        return shopCartDao.delete(id);
    }
}
